package com.github.skystardust.lotteryex.lottery.item.imp.require;

import com.github.skystardust.lotteryex.lottery.item.RequireItem;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;

import java.util.Map;
import java.util.UUID;

@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class RequireItemItem extends RequireItem<ItemStack> {
    public RequireItemItem(ItemStack requireObject) {
        super(requireObject);
    }

    public RequireItemItem(UUID uuid, ItemStack requireObject) {
        super(uuid, requireObject);
    }

    public RequireItemItem(Map<String, Object> stringObjectMap) {
        super(stringObjectMap);
        setRequireObject(((ItemStack) stringObjectMap.get("requireObject")));
    }

    @Override
    public boolean hasRequireObject(Player player) {
        return player.getInventory().all(getRequireObject()).isEmpty();
    }

    @Override
    public void takeItem(Player player) {
        PlayerInventory inventory = player.getInventory();
        inventory.removeItem(getRequireObject());
    }
}
